package com.example.mystore.mapper;


import com.example.mystore.model.OrderList;
import org.apache.ibatis.annotations.*;

@Mapper
public interface OrderListMapper {

    @Insert("INSERT INTO order_list (uid, order_no, goods_id, goods_name, icon_url, price, quantity, total_price, created, updated) " +
            "VALUES (#{uid}, #{orderNo}, #{goodsId}, #{goodsName}, #{iconUrl}, #{price}, #{quantity}, #{totalPrice}, #{created}, #{updated})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertOrderList(OrderList orderList);

    @Select("SELECT * FROM order_list WHERE id = #{id}")
    OrderList getOrderListById(Integer id);


    @Update("UPDATE order_list SET uid = #{uid}, order_no = #{orderNo}, goods_id = #{goodsId}, goods_name = #{goodsName}, icon_url = #{iconUrl}, " +
            "price = #{price}, quantity = #{quantity}, total_price = #{totalPrice}, created = #{created}, updated = #{updated} " +
            "WHERE id = #{id}")
    void updateOrderList(OrderList orderList);

    @Delete("DELETE FROM order_list WHERE id = #{id}")
    void deleteOrderList(Integer id);

    @Select("SELECT * FROM order_list WHERE order_no = #{orderNo}")
    @Results(id = "orderlistResultMap", value = {
            @Result(property = "orderNo", column = "order_no")
    })
    OrderList getOrderListsByOrderId(@Param("orderNo") Integer orderNo);
}
